package com.dhemery.mack.adapters.tests;

import static org.junit.Assert.*;

import org.eclipse.ui.IEditorInput;
import org.junit.Test;

import com.dhemery.mack.adapters.NodeEditorInput;
import com.dhemery.mack.model.Folder;
import com.dhemery.mack.model.Node;
import com.dhemery.mack.model.Session;

public class NodeEditorInputToolTipTextTests extends NodeEditorInputTests {

	@Test
	public void sessionToolTipTextIsEmptyString() {
		Session session = new Session();
		IEditorInput input = new NodeEditorInput(session, null);
		
		assertEquals("", input.getToolTipText());
	}

	@Test
	public void firstChildOfSessionMarkedAsFirst() {
		Session session = new Session();
		Node node = new Node("node");
		session.addNode(node);
		IEditorInput input = new NodeEditorInput(node, null);

		String expectedToolTipText = "{1:" + node.getName() + "}";

		assertEquals(expectedToolTipText, input.getToolTipText());
	}

	@Test
	public void secondChildOfSessionMarkedAsSecond() {
		Session session = new Session();
		session.addNode(new Node("node"));
		Node node = new Node("node");
		session.addNode(node);
		IEditorInput input = new NodeEditorInput(node, null);

		String expectedToolTipText = "{2:" + node.getName() + "}";
		assertEquals(expectedToolTipText, input.getToolTipText());
	}

	@Test
	public void nthChildOfSessionMarkedAsNth() {
		Session session = new Session();
		session.addNode(new Node("node"));
		session.addNode(new Node("node"));
		session.addNode(new Node("node"));
		session.addNode(new Node("node"));
		Node node = new Node("node");
		session.addNode(node);
		IEditorInput input = new NodeEditorInput(node, null);

		String expectedToolTipText = "{5:" + node.getName() + "}";
		assertEquals(expectedToolTipText, input.getToolTipText());
	}

	@Test
	public void grandChildOfSessionHasParentStepAndSelfStep() {
		Session session = new Session();
		Folder parent = new Folder("parent");
		Node node = new Node("node");
		session.addNode(parent);
		parent.addNode(node);
		IEditorInput input = new NodeEditorInput(node, null);

		String parentStep = "{1:" + parent.getName() + "}";
		String selfStep = "{1:" + node.getName() + "}";
		String expectedToolTipText = parentStep + selfStep;
		assertEquals(expectedToolTipText, input.getToolTipText());
	}

	@Test
	public void descendentOfSessionHasStepsForEachAncestorInOrder() {
		Session session = new Session();
		Folder greatGreatGrandParent = new Folder("great great grandparent");
		Folder greatGrandParent = new Folder("great grandparent");
		Folder grandParent = new Folder("grandparent");
		Folder parent = new Folder("parent");
		Node node = new Node("node");
		session.addNode(greatGreatGrandParent);
		greatGreatGrandParent.addNode(greatGrandParent);
		greatGrandParent.addNode(grandParent);
		grandParent.addNode(parent);
		parent.addNode(node);
		IEditorInput input = new NodeEditorInput(node, null);

		String greatGreatGrandParentStep = "{1:" + greatGreatGrandParent.getName() + "}";
		String greatGrandParentStep = "{1:" + greatGrandParent.getName() + "}";
		String grandParentStep = "{1:" + grandParent.getName() + "}";
		String parentStep = "{1:" + parent.getName() + "}";
		String selfStep = "{1:" + node.getName() + "}";
		String expectedToolTipText = greatGreatGrandParentStep + greatGrandParentStep + grandParentStep + parentStep + selfStep;
		assertEquals(expectedToolTipText, input.getToolTipText());
	}
}
